package com.xy.iot.common.result.message;

import com.xy.iot.common.enums.CommandEnum;
import com.xy.iot.common.enums.MessageFormatDataEnum;
import com.xy.iot.common.result.message.base.BaseMessageData;
import com.xy.iot.common.utils.IntegerToByteUtil;
import com.xy.iot.common.utils.IpUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: niuniu
 * @Date: 2024/6/10 17:13
 * @Description: 专门与读写器ping命令的返回值
 */
public class ClientPingMessageData extends BaseMessageData {

    public ClientPingMessageData() {
        this.setDataType(MessageFormatDataEnum.UTF_8.getKey());
        this.setDeviceIp(IpUtil.getHostIp());
        this.setDeviceGroup(IpUtil.getHostName());
        this.setCommand(CommandEnum.CLIENT_PING.getKey());
        if (super.getCommandData() == null){
            //16进制位数byte[]转换成十进制
            Map<String, Object>  objectMap = new HashMap<>();
            objectMap.put("ping", IntegerToByteUtil.bytesToInt(PING_BYTES));
            setCommandData(objectMap);
        }
    }
}
